package user

import (
	"context"
	"go.uber.org/zap"
	"user_srv/config"
	"user_srv/internal/model/dao"
	__ "user_srv/proto"
)

// 定义空接口
type UserInfoService struct {
	__.UnimplementedUserInfoServiceServer
}

// 实现方法
func (s *UserInfoService) UserRegister(ctx context.Context, req *__.UserRegisterRequest) (resp *__.UserRegisterResponse, err error) {
	var user dao.User
	config.DB.Where("name=? and mobile=?", req.Name, req.Mobile).Limit(1).Find(&user)
	if user.ID != 0 {
		zap.S().Error("该用户已经被注册")
		return
	}
	d := dao.User{
		Name:     req.Name,
		Password: req.Password,
		Mobile:   req.Mobile,
	}
	config.DB.Create(&d)
	return &__.UserRegisterResponse{Id: int32(d.ID)}, nil
}
